package strStr

func strStr(haystack string, needle string) int {
	if needle == "" {
		return 0
	}

	l := len(haystack)
	n := len(needle)
	pre := 0
	for {
		if pre > l-n {
			return -1
		}
		if haystack[pre] != needle[0] {
			pre++
			continue
		}
		for i := 0; i < n; i++ {
			if haystack[pre+i] == needle[i] {
				if i == n-1 {
					return pre
				}
				continue
			}
			pre++
			break
		}
	}
}
